package com.shao;

import com.shao.discovery.Registry;
import com.shao.proxy.handler.SrpcConsumerInvocationHandler;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @author PaoFu
 * @version 1.0
 * @data 2025/4/3 16:16
 */
@Data
public class ReferenceConfig<T> {

    private static final Logger log = LoggerFactory.getLogger(ReferenceConfig.class);
    private Class<T> Interface;

    private static int port = 8088;

    private Registry registry;

    @SuppressWarnings("all")
    public T get() {
        // 使用动态代理生成对象
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Class<?>[] classes = new Class[]{Interface};
        InvocationHandler invocationHandler = new SrpcConsumerInvocationHandler(registry, Interface);
        return (T) Proxy.newProxyInstance(classLoader, classes, invocationHandler);
    }
}
